use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    println!("猜数字游戏");

	let secret_number = rand::thread_rng().gen_range(1..=100);

	// println!("秘密数字是：{}", secret_number);

	loop {
		println!("输入你的猜测：");

		let mut guess = String::new();
	
		io::stdin().read_line(&mut guess)
			.expect("读取一行失败");
		
		let guess: u32 = match guess.trim().parse() {
			Ok(num) => num,
			Err(_) => continue
		};
	
		println!("你猜的数字为：{}", guess);
	
		match guess.cmp(&secret_number) {
			Ordering::Less => println!(" 太小!"),
			Ordering::Greater => println!(" 太大!"),
			Ordering::Equal => {
				println!(" 你赢了!");
				break;
			}
		}
	}
}
